using System.ComponentModel.DataAnnotations;
using System.Linq;
using NUnit.Framework;
using SharpTestsEx;

namespace AltNetHispano.Vale.DataAnnotations.Tests
{
	[TestFixture]
	public class DataAnnotationsInspectorTest
	{
		public class Person
		{
			[Required(ErrorMessage = "Name is required")]
			public string Name { get; set; }
		}

		[Test]
		public void CanGetValidationDelegateForName()
		{
			var inspector = new DataAnnotationsInspector();
			var constraint = inspector.GetConstraints<Person>().First();
			
			constraint(new Person {Name = null})
				.Should().Be.EqualTo("Name is required");
		}


		[Test]
		public void ValidationDelegateReturnStringEmptyIfPropertyValueIsValid()
		{
			var inspector = new DataAnnotationsInspector();
			var constraint = inspector.GetConstraints<Person>().First();

			constraint(new Person { Name = "Juan" })
				.Should().Be.Empty();
		}
	}
}